<!-- author: xuett -->
<!-- date: 2024-06-18 11:46:17 -->
<!-- description: echarts首页 -->
<template>
  <div class="chart-content">
    <div class="chart-type" v-for="typeItem in chartList" :key="typeItem.type">
      <div class="type-name">{{ typeItem.name }}</div>
      <div class="chart-list">
        <div class="chart-item" v-for="chart in typeItem.list" @click="previewChart(chart)">
          <img :src="getImg(chart.img)" alt="" />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import chartList from "./json/chartList.json";

const getImg = (img) => {
  return new URL(`../../assets/img-echarts/${img}`, import.meta.url).href;
};

const $router = useRouter();

const previewChart = (chart) => {
  $router.push({
    path: "/echarts-preview",
    query: {
      name: chart.comName
    }
  });
};
</script>

<style scoped lang="scss">
.chart-content {
  width: 100%;
  padding: 15px 15px 0;
  .chart-type {
    width: 100%;
    .type-name {
      font-size: 16px;
      font-weight: bold;
      line-height: 32px;
    }
    .chart-list {
      width: 100%;
      display: flex;
      flex-wrap: wrap;
      .chart-item {
        width: calc((100% - 45px) / 4);
        height: 300px;
        margin: 0 15px 15px 0;
        border-radius: 4px;
        overflow: hidden;
        box-shadow: 0 0 10px 5px rgba(0, 0, 0, 0.1);
        &:nth-child(4n) {
          margin-right: 0;
        }
        &:hover {
          img {
            transform: scale(1.05);
          }
        }
        img {
          display: block;
          width: 100%;
          height: 100%;
          transition: all 0.3s;
        }
      }
    }
  }
}
</style>
